package com.haifeng.mywriteaidldemo;

import android.os.Bundle;
import android.text.TextUtils;
import android.widget.EditText;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.haifeng.mywriteaidldemo.MyAIDL.MyInterface;

public class ProcessActivity extends AppCompatActivity {

    TextView btn_add,btn_get,tv_show;
    EditText write_name;

    MyInterface interfacs;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_process);
        MyServiceConnection.BindService();
        initView();

    }

    void initView(){
        btn_add=findViewById(R.id.textView5);
        btn_get=findViewById(R.id.textView3);
        tv_show=findViewById(R.id.textView4);
        write_name=findViewById(R.id.editTextTextPersonName);

        btn_get.setOnClickListener(view ->{
            //特此注意当使用远程时 在获取远程服务的代理类
            interfacs=MyServiceConnection.getInstance().getInterfacs();
            if (interfacs!=null){
                if (!TextUtils.isEmpty(write_name.getText().toString())){
                    if (interfacs!=null){
                       String name= interfacs.getname(write_name.getText().toString());
                        tv_show.setText(TextUtils.isEmpty(name)?"error":name);
                    }
                }
            }
        });
        btn_add.setOnClickListener(view -> {
            //特此注意当使用远程时 在获取远程服务的代理类
            interfacs=MyServiceConnection.getInstance().getInterfacs();

            if (!TextUtils.isEmpty(write_name.getText().toString())){
                if (interfacs!=null){
                    interfacs.addname(write_name.getText().toString());
                }
            }
        });
    }
}
